<template>
  <div style="font-size: 12px; line-height: 60px; display: flex;">
    <div style="flex: 1; font-size: 20px">
      <span :class="collapseBtnClass" style="cursor: pointer" @click="collapse"></span>
      <el-breadcrumb separator="/" style="display: inline-block; margin-left: 10px">
        <el-breadcrumb-item :to="'/backHome'">后台首页</el-breadcrumb-item>
        <el-breadcrumb-item>{{ currentPathName }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-dropdown style="height: 50px; cursor: pointer">
      <div style="display: inline-block">
        <img :src="user.avatarUrl" alt="头像"
             style="width: 50px;height: 50px; border-radius: 50%; position: relative; top: 5px; right: 5px">
        <span style="margin-left: 5px;font-size: 16px; position: relative; top: -12px; left: 1px;">{{ user.nickname }}
          <el-tag v-if="user.role==='ROLE_USER'">普通用户</el-tag>
            <el-tag v-if="user.role==='ROLE_ADMIN'">管理员</el-tag>
            <el-tag v-if="user.role==='ROLE_STUDENT'">学生</el-tag>
            <el-tag v-if="user.role==='ROLE_TEACHER'">教师</el-tag>
          <i class="el-icon-arrow-down" style="margin-left: 5px"></i></span>
      </div>
      <el-dropdown-menu slot="dropdown" style="width: 160px;text-align: center;line-height: 500px">
        <el-dropdown-item style="font-size: 14px; padding: 5px 0" ><span @click="$router.push('/manage')" >返回前台</span></el-dropdown-item>
        <el-dropdown-item style="font-size: 14px; padding: 5px 0" ><span @click="logout">退 出</span></el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>

import {setRoutes} from "@/router";
export default {
  name: "Header",
  props: {
    collapseBtnClass: String,
    collapse:'',
  },
  computed: {
    currentPathName () {
      return this.$store.state.currentPathName;　　//需要监听的数据
    }
  },
  data(){
    return {
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
      drawer: false,
      innerDrawer: false,
      form:{},
    }
  },
  inject: ['reload'],
  created() {
    this.request.get("/user/username/" + this.user.username).then(res=>{
      if (res.code==='200'){
        this.form = res.data
        this.user.ID=res.data.accountId
        this.user.username=res.data.username
        this.user.nickname=res.data.nickname
        this.user.phone=res.data.phone
        this.user.address=res.data.address
        this.user.email=res.data.email
        this.user.avatarUrl=res.data.avatarUrl
      }
      this.$forceUpdate();
    })
  },
  methods: {
    logout() {
      this.$store.commit("logout")
      this.$message.success("退出成功")
    },

  },

}
</script>

<style scoped>

</style>